package org.hisp.dhis.

import java.util.Vector;
import the orgunitservice

/*	this class is used by creating a BrowseOrgUnits object and calling the getNextLevelUnits method
	BrowseOrgUnit bou = new BrowseOrgUnits()     
	bou.getNextLevelUnits() then returns the orgunits at that level - orgUnitsAtLevel
	
	like iterate through the orgunits and get their name - getName() into a string array
	then pass string array for use for List
	new ChoiceItem(string[] orgunitnames)
*/

Class BrowseOrgUnits{

	//currentorgunits for display by list
	//Collection currentOrgUnits;
	Collection orgUnitsAtLevel;
	int currentLevel = 0;

	OrgUnitService ous = new OrgUnitService(); //or what ever implementation gives us access to data from the service
	
	public BrowseOrgUnits(){
		//this.getNextLevelUnits();
	}
	
	private Collection getFirstLevelOrgUnits(){
		// get the root (first level) orgunits from the DHIS
		currentOrgUnits = ous.getRootOrganisationUnits();
		//set current level as level 1
		currentlevel = 1;
	}
	
	public Collection getNextLevelUnits(int id){
		orgUnitsAtLevel = new Vector();
		
		if (currentOrgUnits == null){
			orgUnitsAtLevel = this.getFirstLevelOrgUnits();
			currentlevel = 1;
			
		}
		else if(currentOrgUnits != null && currentLevel != 0){
			
			//get the particular orgunitname selected and get its object and get its id 
			//this should preferably be done in the calling class and passed in
			//then use its id to get the orgunit children it has from the DHIS
			
			orgUnitAtLevel = ous.getOrganisationUnitWithChildren(int id)
			//you could remove the first element, we dont need the first element
			
			//then return these orgunits  out
			
			currentOrgUnits = orgUnitAtLevel;
		}
		
		currentOrgUnits = orgUnitAtLevel;
		return orgUnitsAtLevel;
	}

}